package com.example.video.common.util;

import com.example.video.admin_server.entity.SysRole;
import com.example.video.common.security.SysUserDetails;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.List;

/**
 * <p>
 * <p>
 * <p/>
 *
 * @author : yj
 */
public class SysUserUtils {

    public static List<SysRole> getRoles(){
        return getUserDetails().getRoles();
    }

    public static SysUserDetails getUserDetails(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        SysUserDetails userDetails = (SysUserDetails)authentication.getPrincipal();
        return userDetails;
    }
}
